﻿using Autofac;
using WebAppTemplate.CSR.Repository.DbContexts;
using WebAppTemplate.CSR.Service;

namespace WebAppTemplate.CSR.WebAPI
{
    public class AppModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            var repositoryAssembly = typeof(AppDbContext).Assembly;
            var serviceAssembly = typeof(IService).Assembly;

            builder.RegisterAssemblyTypes(repositoryAssembly)
                .Where(t => t.Name.EndsWith("Repository"))
                .AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(serviceAssembly)
                .Where(t => t.Name.EndsWith("Service"))
                .AsImplementedInterfaces();

            builder.RegisterType<AppQueryContext>().AsSelf().InstancePerLifetimeScope();
        }
    }
}
